package com.example.mynetwork2.mvpdesign2.view;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.mynetwork2.R;
import com.example.mynetwork2.login.utils.Utils;
import com.example.mynetwork2.mvpdesign2.presenter.CidianPresenter;


public class FanyiAct2  extends AppCompatActivity  implements  IFanyiView{
    private EditText et;
    private TextView tv;
    private   CidianPresenter cidianPresenter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mvp_indexactivity_layout);
        init();
    }

    @Override
    public void init() {
        et = (EditText) findViewById(R.id.input_word_et);
        tv = (TextView) findViewById(R.id.fanyi_tv);
        Button fanyi_bt = findViewById(R.id.fanyi_bt);
        cidianPresenter = new CidianPresenter(this);
        fanyi_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String input = et.getText().toString();
                if (Utils.isEmpty(input)){//如果输入为空去点击查询按钮
                    Toast.makeText(FanyiAct2.this,"查询内容不能为空",Toast.LENGTH_SHORT);
                    return;
                }
                cidianPresenter.inputToModel(input);
            }
        });
    }

    @Override
    public void setInfo(String str) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                tv.setText(str);
            }
        });


    }

    @Override
    public void setError() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(FanyiAct2.this,"出错了",Toast.LENGTH_SHORT);

            }
        });
    }

}
